var app = getApp();
var $ = require("../../utils/httpHelper.js")
var touchDot = 0;//触摸时的原点  
var time = 0;// 时间记录，用于滑动时且时间小于1s则执行左右滑动  
var interval = "";// 记录/清理时间记录
Page({

  /**
   * 页面的初始数据
   */
  data: {
    objarr: [],
    page: 1,
    pagesize: 6,
    totalpage: 0,//最大页数
    height: 0,
    nomore: true,
    del: false,
    showDialog:false,
    num:0,
    good_id:0
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight })
      }
    })
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      page: this.data.page,
      pagesize: this.data.pagesize
    }
    $.httpPost("good_list_jifen", params, (data, err) => {
      this.setData({
        objarr: data.data.lists,
        totalpage: data.data.total_page
      })
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("xila")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize
      }
      $.httpPost("good_list_jifen", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },

  todh: function (e) {
    let id = e.currentTarget.dataset.id
    let num = e.currentTarget.dataset.num
    this.setData({
      showDialog: true,
      num:num,
      good_id:id
    })
    
  },
  checkinfo(name,phone,addr) {
    if (app.check_empty(name) || app.check_empty(phone) || app.check_empty(addr)) {
      wx.showToast({
        title: '不能是空',
      })
      return false
    } else {
      if (app.checkPhone(phone)){
        return true
      }else{
        wx.showToast({
          title: '手机格式不正确',
        })
        return false
      }
      
    }
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let name = e.detail.value.username
    let phone = e.detail.value.userphone
    let addr = e.detail.value.addr
    if (this.checkinfo(name,phone,addr)){
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        good_id: this.data.good_id,
        name:name,
        phone:phone,
        address:addr
      }
      $.httpPost("get_good_jifen", params, (data, err) => {
        this.setData({
          showDialog: false
        })
        wx.showToast({
          title: data.message,
          duration: 2000,
        })
        if(data.result == 'success'){
          
        }
      })
    }
  },

  formReset: function () {
    this.setData({
      showDialog: false
    })
  }
  

})